package aes.gui;

import java.awt.CardLayout;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JSeparator;
import javax.swing.border.EmptyBorder;

import aes.general.Admin;
import aes.general.AdminControl;

/**
 * This is the frame of the admin. 
 * This frame provides every option the admin have
 * according to the requirements.
 *
 */
public class AdminFrame extends JFrame {

	/**
	 * 
	 */

	private static final long serialVersionUID = 1L;
	private JPanel contentPane=null;
	private JPanel AdminMain=null;
	private JPanel ExamsPanel;
	private JPanel QuestionsPanel;
	private JPanel ReportsPanel;
	private JPanel viewReq;
	private JLabel l1;
	private JButton b1;
	private JButton b3;
	private JButton b4;
	private JButton b5;
	private JButton LogOut;
	private Admin admin;
	/**
	 * Launch the application.
	 */
	private ArrayList<String> Requests = new ArrayList<String>();
	private ArrayList<String> temp = new ArrayList<String>();
	
	public AdminFrame(Admin admin)
	{
		super();
		initialize();
		this.admin=admin;
	}
	

	public AdminFrame() {
		super();
		initialize();
		this.admin=admin;
	}


	/**
	 * Create the frame.
	 */
	public void initialize() {
		
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setBounds(100, 100, 640, 480);
		this.setTitle("Admin");
		
		contentPane = new JPanel();		
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(new CardLayout(0, 0));
		
		AdminMain = new JPanel();
		AdminMain.setBounds(0, 0, 624, 442);
		contentPane.add(AdminMain,"AdminMain");
		AdminMain.setLayout(null);
		
		l1 = new JLabel("Welcome");
		l1.setBounds(261, 11, 92, 29);
		l1.setFont(new Font("Tempus Sans ITC", Font.BOLD, 21));
		AdminMain.add(l1);
		
		b1 = new JButton("View Requests");
		b1.setBounds(325, 174, 125, 23);
		AdminMain.add(b1);
		b1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				temp.clear();
				AdminControl.getRequests(temp);
				try {
					Thread.sleep(500);
				} catch (InterruptedException e1) {
					e1.printStackTrace();
				}
				Requests = AdminControl.getReq();
				if(Requests.size()<=1)
					JOptionPane.showMessageDialog(null,
							" No Requests Found!", "",
							JOptionPane.INFORMATION_MESSAGE);
				else{
				viewReq = new AdminReqPanel(contentPane,Requests);
				contentPane.add(viewReq, "AdminReqPanel");
				CardLayout cl = (CardLayout) (contentPane.getLayout());
				cl.show(contentPane, "AdminReqPanel");}
			}
		});
		
			
		b3 = new JButton("View Exams");
		b3.setBounds(325, 98, 125, 23);
		AdminMain.add(b3);
		b3.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				temp.clear();
				AdminControl.ViewExams(temp);
				ExamsPanel = new AdminViewExamsPanel(contentPane);
				contentPane.add(ExamsPanel,"exams");
				CardLayout cl = (CardLayout) (contentPane.getLayout());
				cl.show(contentPane, "exams");
				
			}
		});
		
		b4 = new JButton("Get Reports");
		b4.setBounds(174, 174, 125, 23);
		AdminMain.add(b4);
		b4.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				ReportsPanel = new AdminReportsPanel(contentPane);
				contentPane.add(ReportsPanel,"reports");
				CardLayout cl = (CardLayout) (contentPane.getLayout());
				cl.show(contentPane, "reports");
			}
		});
		
		b5 = new JButton("View Questions");
		b5.setBounds(174, 98, 125, 23);
		AdminMain.add(b5);
		b5.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				temp.clear();
				AdminControl.ViewQuestions(temp);
				QuestionsPanel = new AdminViewQuestionsPanel(contentPane);
				contentPane.add(QuestionsPanel,"questions");
				CardLayout cl = (CardLayout) (contentPane.getLayout());
				cl.show(contentPane, "questions");
			}
		});
		
		LogOut = new JButton("Log out");
		LogOut.setBounds(252, 287, 125, 23);
		AdminMain.add(LogOut);
		LogOut.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				dispose();
				LoginFrame login = new LoginFrame();
				login.setVisible(true);
			}
		});
		
	}
}
